import notFoundImg from '@/assets/images/nocourse.png'
import { CouponInfo, OrderConfirm, PrepaidCardInfo } from '@/types/orderConfirm'
import { getUserSelectList, getConfirmUpdatePrice } from '@/api/prepaidCard'
import OrderCouponList from './orderCouponList'
import React, { FC, useEffect, useState } from 'react'
import { useAsyncEffect } from 'ahooks'
import { XBusinesslineId } from '@/constants'
import { CourseId } from '@/types'
import { ResPrepaidCard } from '@/types/prepaidCard'
import { Product } from '@/types/product'
import { useAppSelector } from '@/store'
import { selectCardUpdatePriceInfo } from '@/store/confirmPay'

const payAttention: FC<{
  couponInfo: CouponInfo
  course_id: CourseId
  balance: string | number
  paymentData: OrderConfirm
  productInfo: Product[]
  // orderCoupon :
}> = (props) => {
  // 注：若商品申请退费时讲义已签收，需根据签收的讲义按分类扣除费用。

  const [select, setSelect] = useState(false)
  //   const cardUpdatePriceInfo = useAppSelector(selectCardUpdatePriceInfo)
  /**价格更新 */
  const getCouponPriceStr = () => {
    const cardUpdatePriceInfo = useAppSelector(selectCardUpdatePriceInfo)
    let couponPriceStr = ''
    if (cardUpdatePriceInfo.couponInfo && cardUpdatePriceInfo.couponInfo.isChecked) {
      couponPriceStr = cardUpdatePriceInfo.couponInfo.couponPriceStr
    } else if (
      cardUpdatePriceInfo.couponProm &&
      cardUpdatePriceInfo.couponProm.coupon_detail.length > 0
    ) {
      couponPriceStr = '' + cardUpdatePriceInfo.couponProm.coupon_detail.length + '张可用'
    } else {
      couponPriceStr = ''
    }
    return couponPriceStr
  }

  return (
    <>
      <div className=" w-full clear-both leading-r1.6  text-gray-333333 text-r1.4 font-normal pt-r1.3 ">
        <span className=" float-left ">优惠券</span>
        {props.couponInfo.couponTxt ? (
          <span className=" border-red-FF3627 text-red-FF3627 border-solid border font-normal  text-r1.2 ml-r1.0 ">
            {props.couponInfo.couponTxt}
          </span>
        ) : null}
        <span
          className=" float-right font-medium text-gray-999999  leading-r1.2 text-r1.2 "
          onClick={() => {
            setSelect(true)
          }}
        >
          {getCouponPriceStr() || props.couponInfo.couponPriceStr || '无可用'}
          <i className=" iconfont icon-icon_arrow_right  relative top-r0.2"></i>
        </span>
      </div>
      {select ? (
        <OrderCouponList
          balance={props.balance}
          paymentData={props.paymentData}
          productInfo={props.productInfo}
          course_id={props.course_id}
          setVisible={setSelect}
        ></OrderCouponList>
      ) : null}
    </>
  )
}

export default payAttention
